import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)


export const constantRoutes = [
  {
    path: '/',
    name: 'Login',
    component: () => import('./views/login/Login.vue')

  },
  {
    path: '/login',
    name: 'login',
    component: () => import('./views/login/Login.vue')

  },
  {
    path: '/home',
    name: "Home",
    redirect: '/home/chat',
    component: () => import('./views/home/Home.vue'),
    children: [
      {
        path: 'chat',
        name: 'Chat',
        component: () => import("./views/chat/index.vue")
      }, 
      {
        path: 'user',
        name: 'User',
        component: () => import("./views/user/index.vue")
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
